//
//  FingerView.m
//  AppFinance
//
//  Created by wei on 12-6-21.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "AFFingerView.h"

#import <QuartzCore/QuartzCore.h>
#import "AFMarketData.h"
#import "AFSetting.h"
#import "AFUtils.h"
#import "MarketKpiInfo.h"
#define K_FINGER_S_X  [AFSetting QUARTZ_KLINE_W] / 2
#define K_FINGER_CENTER_X [AFSetting QUARTZ_KLINE_W] / 2

// 分时图信息
float TIME_LINE_W = 1.0f;

float TIME_LINE_1_X;
float TIME_LINE_1_Y;
float TIME_LINE_1_H;

float TIME_LINE_2_X;
float TIME_LINE_2_Y;
float TIME_LINE_2_H;

CGRect RECT_TIME_INFO;
CGRect RECT_TIME_INFO_RIGHT;
CGRect RECT_TIME_LINE_1;
CGRect RECT_TIME_LINE_2;

// K线图信息
float KLINE_LINE_W = 1.0f;

float KLINE_LINE_1_X;
float KLINE_LINE_1_Y;
float KLINE_LINE_1_H;

float KLINE_LINE_2_X;
float KLINE_LINE_2_Y;
float KLINE_LINE_2_H;

CGRect RECT_KLINE_INFO;
CGRect RECT_KLINE_INFO_RIGHT;
CGRect RECT_KELIN_LINE_1;
CGRect RECT_KELIN_LINE_2;

@implementation AFFingerView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        // 分时图坐标
        TIME_LINE_1_X = K_FINGER_S_X;
        TIME_LINE_1_Y = 0;
        TIME_LINE_1_H = 180;
        
        TIME_LINE_2_X = K_FINGER_S_X;
        TIME_LINE_2_Y = 188;
        TIME_LINE_2_H = 70;
        
        // K线图坐标
        KLINE_LINE_1_X = K_FINGER_S_X;
        KLINE_LINE_1_Y = 0;
        KLINE_LINE_1_H = 178;
        
        KLINE_LINE_2_X = K_FINGER_S_X;
        KLINE_LINE_2_Y = 181;
        KLINE_LINE_2_H = 65;
        
        
        // iPhone5 set
//        if ([AFUtils currentResolution] == UIDevice_iPhone5) {
//            TIME_LINE_2_H += AF_IPHONE5_H_OFFSET;
//            KLINE_LINE_2_H += AF_IPHONE5_H_OFFSET;
//        }
        
        // 分时图信息
        RECT_TIME_INFO = CGRectMake(0, 0, 80, 92);
        RECT_TIME_INFO_RIGHT = CGRectMake(190, 0, 80, 92);
        RECT_TIME_LINE_1 = CGRectMake(TIME_LINE_1_X, TIME_LINE_1_Y, TIME_LINE_W, TIME_LINE_1_H);
        RECT_TIME_LINE_2 = CGRectMake(TIME_LINE_2_X, TIME_LINE_2_Y, TIME_LINE_W, TIME_LINE_2_H);

        // K线图信息
        
        if([AFUtils currentResolution] == UIDevice_iPhone5){
        RECT_KLINE_INFO = CGRectMake(0, -32, 568, 30);
        }else{
        RECT_KLINE_INFO = CGRectMake(0, -32, 480, 30);
        }
        RECT_KELIN_LINE_1 = CGRectMake(KLINE_LINE_1_X, KLINE_LINE_1_Y, KLINE_LINE_W, KLINE_LINE_1_H);
        RECT_KELIN_LINE_2 = CGRectMake(KLINE_LINE_2_X, KLINE_LINE_2_Y, KLINE_LINE_W, KLINE_LINE_2_H);
        
        if([AFSetting QUARTZ_KLINE_W] < 270){
            KLINE_LINE_1_X = K_FINGER_S_X;
            KLINE_LINE_1_Y = 0;
            KLINE_LINE_1_H = 240;
            
            KLINE_LINE_2_X = K_FINGER_S_X;
            KLINE_LINE_2_Y = 245;
            KLINE_LINE_2_H = 85;
            if([AFUtils currentResolution] != UIDevice_iPhone5){
                 KLINE_LINE_1_H -= 50.0f;
                 KLINE_LINE_2_Y -= 50.0f;
                 KLINE_LINE_2_H -= 38.0f;
                
                
            }
            RECT_KLINE_INFO = CGRectMake(0, -39, 320, 33);
            RECT_KLINE_INFO_RIGHT = CGRectMake(0, -39, 320, 33);
            RECT_KELIN_LINE_1 = CGRectMake(KLINE_LINE_1_X, KLINE_LINE_1_Y, KLINE_LINE_W, KLINE_LINE_1_H);
            RECT_KELIN_LINE_2 = CGRectMake(KLINE_LINE_2_X, KLINE_LINE_2_Y, KLINE_LINE_W, KLINE_LINE_2_H);
            
        }
       
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

// 1: time 2:kline
-(void) fingerViewType:(int)type{
    fingerType = type;
    
    [self showView];
}

-(void) showView{
    [self createInfoView];
}

-(void)createInfoView{

    if (fingerType == AF_K_MARKET_FINGER_VIEW_TYPE_TIME) {
        _showInfo = [[UIView alloc] initWithFrame:RECT_TIME_INFO];
        
        [self timeInfoView];
        
        line1 = [[UILabel alloc] initWithFrame:RECT_TIME_LINE_1];
        [line1 setBackgroundColor: [UIColor whiteColor]];
        
        line2 = [[UILabel alloc] initWithFrame:RECT_TIME_LINE_2];
        [line2 setBackgroundColor: [UIColor whiteColor]];
    } else {
        
         _showInfo = [[UIView alloc] initWithFrame:RECT_KLINE_INFO];
//        [_showInfo.layer setBorderWidth:0.5];
        
//        [_showInfo.layer setBorderColor:[[UIColor cyanColor] CGColor]];
        [self klineInfoView];
        
        if(line1){
            [line1 removeFromSuperview];
            line1 = nil;
        }
        line1 = [[UILabel alloc] initWithFrame:RECT_KELIN_LINE_1];
//        [line1 setBackgroundColor: [UIColor whiteColor]];
        //十字线 颜色
        [line1 setBackgroundColor: [UIColor grayColor]];
        
        if(line2){
            [line2 removeFromSuperview];
            line2 = nil;
        }
        line2 = [[UILabel alloc] initWithFrame:RECT_KELIN_LINE_2];
//        [line2 setBackgroundColor: [UIColor whiteColor]];
        [line2 setBackgroundColor: [UIColor grayColor]];
        
        if(line3){
            [line3 removeFromSuperview];
            line3 = nil;
        }
        line3 = [[UILabel alloc] initWithFrame:CGRectMake(0, [AFSetting QUARTZ_KLINE_H] / 2, [AFSetting QUARTZ_KLINE_W], KLINE_LINE_W)];
        //        [line2 setBackgroundColor: [UIColor whiteColor]];
        [line3 setBackgroundColor: [UIColor grayColor]];
//        pointImage = [[UIImageView alloc]initWithFrame:CGRectMake([AFSetting QUARTZ_KLINE_W]  / 2, [AFSetting QUARTZ_KLINE_H] / 2, 12,12)];
//        pointImage.image = [UIImage imageNamed:@"market_point.png"];
        if(PointLab){
            [PointLab removeFromSuperview];
            PointLab = nil;
        }
        
        PointLab = [[UILabel alloc] initWithFrame:CGRectMake([AFSetting QUARTZ_KLINE_W], [AFSetting QUARTZ_KLINE_H] / 2, 45, 15)];
        [PointLab setBackgroundColor: [UIColor grayColor]];
        [PointLab setTextColor:[UIColor whiteColor]];
        [PointLab setFont:[UIFont systemFontOfSize:10]];
        PointLab.textAlignment = NSTextAlignmentLeft;
        PointLab.adjustsFontSizeToFitWidth = YES;
        PointLab.minimumScaleFactor = 0.5;
        
    }
    
    [self addSubview:line1];
    [self addSubview:line2];
     [self addSubview:line3];
    
    [self addSubview:_showInfo];
    [self bringSubviewToFront:_showInfo];
    [self addSubview:PointLab];
//    [self addSubview:pointImage];
    
    // 初始未知
    [self finagerMoveX:K_FINGER_S_X];
}

-(void)timeInfoView{
    
    UIFont *font = [UIFont systemFontOfSize:12.0];
    
    UIColor *info_bgcolor = [UIColor colorWithRed:50.0f/255.0f green:50.0f/255.0f blue:50.0f/255.0f alpha:1.0];
    [_showInfo setBackgroundColor:info_bgcolor];
    [_showInfo.layer setBorderWidth:0.5];
    //[_showInfo.layer setBorderColor:[[UIColor redColor] CGColor]];
    
    _priceLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 24, 30)];
    _averageLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 24, 30)];
    _dateLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 60, 24, 30)];
    
    _priceLab.text = @"价格";
    [_priceLab setFont:font];
    [_priceLab setBackgroundColor:[UIColor clearColor]];
    [_priceLab setTextColor:[UIColor whiteColor]];
    
    _averageLab.text = @"均价";
    [_averageLab setFont:font];
    [_averageLab setBackgroundColor:[UIColor clearColor]];
    [_averageLab setTextColor:[UIColor whiteColor]];
    
    _dateLab.text = @"时间";
    [_dateLab setFont:font];
    [_dateLab setBackgroundColor:[UIColor clearColor]];
    [_dateLab setTextColor:[UIColor whiteColor]];
    
    
    _price = [[UILabel alloc] initWithFrame:CGRectMake(24, 0, 54, 30)];
    [_price setFont:font];
    [_price setBackgroundColor:[UIColor clearColor]];
    [_price setTextColor:[UIColor redColor]];
    [_price setTextAlignment:NSTextAlignmentRight];
    
    _average = [[UILabel alloc] initWithFrame:CGRectMake(24, 30, 54, 30)];
    [_average setFont:font];
    [_average setBackgroundColor:[UIColor clearColor]];
    [_average setTextColor:[UIColor greenColor]];
    [_average setTextAlignment:NSTextAlignmentRight];
    
    _date = [[UILabel alloc] initWithFrame:CGRectMake(24, 60, 54, 30)];
    [_date setFont:font];
    [_date setBackgroundColor:[UIColor clearColor]];
    [_date setTextColor:[UIColor whiteColor]];
    [_date setTextAlignment:NSTextAlignmentCenter];
    
    /*
    _volumeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 180, 60, 8)];
    _volumeLab.text = @"成交量";
    [_volumeLab setFont:font];
    [_volumeLab setBackgroundColor:[UIColor clearColor]];
    [_volumeLab setTextColor:[UIColor whiteColor]];
    [_volume setTextAlignment:UITextAlignmentLeft];
    //_volumeLab.adjustsFontSizeToFitWidth = YES; // 自动缩放字体
    //_volumeLab.lineBreakMode = UILineBreakModeTailTruncation;
    */
    
    _volume = [[UILabel alloc] initWithFrame:CGRectMake(0, 180, 80, 8)];
    [_volume setFont:[UIFont systemFontOfSize:10.0]];
    [_volume setBackgroundColor:[UIColor clearColor]];
    [_volume setTextColor:[UIColor whiteColor]];
    [_volume setTextAlignment:NSTextAlignmentLeft];
    
    
    [_showInfo addSubview:_priceLab];
    [_showInfo addSubview:_averageLab];
    [_showInfo addSubview:_dateLab];
    
    [_showInfo addSubview:_price];
    [_showInfo addSubview:_average];
    [_showInfo addSubview:_date];
    
    //[self addSubview:_volumeLab];
    [self addSubview:_volume];
}

-(void)klineInfoView{
    
    if([AFSetting QUARTZ_KLINE_W] >= 270){
        UIFont *font = [UIFont systemFontOfSize:14.0];
        
    if([AFUtils currentResolution] == UIDevice_iPhone5){
        _openName = [[UILabel alloc] initWithFrame:CGRectMake(150, 0, 20, 30)];
        _highName = [[UILabel alloc] initWithFrame:CGRectMake(250, 0, 20, 30)];
        _lowName = [[UILabel alloc] initWithFrame:CGRectMake(350, 0, 20, 30)];
        _closeName = [[UILabel alloc] initWithFrame:CGRectMake(450, 0, 20, 30)];
        _dateName = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 15, 30)];
        
    }else{
        _openName = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 17, 30)];
        _highName = [[UILabel alloc] initWithFrame:CGRectMake(205, 0, 17, 30)];
        _lowName = [[UILabel alloc] initWithFrame:CGRectMake(290, 0, 17, 30)];
        _closeName = [[UILabel alloc] initWithFrame:CGRectMake(375, 0, 17, 30)];
        _dateName = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 15, 30)];
        
    }
    
    
    
    _highName.text = @"高";
    [_highName setFont:font];
    [_highName setBackgroundColor:[UIColor clearColor]];
    [_highName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
    
    _lowName.text = @"低";
    [_lowName setFont:font];
    [_lowName setBackgroundColor:[UIColor clearColor]];
    [_lowName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
    
    _openName.text = @"开";
    [_openName setFont:font];
    [_openName setBackgroundColor:[UIColor clearColor]];
    [_openName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
    
    _closeName.text = @"收";
    [_closeName setFont:font];
    [_closeName setBackgroundColor:[UIColor clearColor]];
    [_closeName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
    
    _dateName.text = @"日期";
    [_dateName setFont:font];
    [_dateName setBackgroundColor:[UIColor clearColor]];
    [_dateName setTextColor:[UIColor blackColor]];
    
    if([AFUtils currentResolution] == UIDevice_iPhone5){
    _open = [[UILabel alloc] initWithFrame:CGRectMake(170, 0, 80, 30)];
     _high = [[UILabel alloc] initWithFrame:CGRectMake(270, 0, 80, 30)];
      _low = [[UILabel alloc] initWithFrame:CGRectMake(370, 0, 80, 30)];
     _close = [[UILabel alloc] initWithFrame:CGRectMake(470, 0, 80, 30)];
     _date = [[UILabel alloc] initWithFrame:CGRectMake(6, 0, 130, 30)];
        
    }else{
        _open = [[UILabel alloc] initWithFrame:CGRectMake(137, 0, 65, 30)];
        _high = [[UILabel alloc] initWithFrame:CGRectMake(222, 0, 65, 30)];
        _low = [[UILabel alloc] initWithFrame:CGRectMake(307, 0, 65, 30)];
        _close = [[UILabel alloc] initWithFrame:CGRectMake(392, 0, 65, 30)];
        _date = [[UILabel alloc] initWithFrame:CGRectMake(3, 0, 110, 30)];
        
    }
    [_open setFont:font];
    [_open setBackgroundColor:[UIColor clearColor]];
    [_open setTextColor:[UIColor blackColor]];
    [_open setTextAlignment:NSTextAlignmentLeft];
    _open.adjustsFontSizeToFitWidth = YES;
    _open.minimumScaleFactor = 0.5;
   
    [_high setFont:font];
    [_high setBackgroundColor:[UIColor clearColor]];
    [_high setTextColor:[UIColor redColor]];
    [_high setTextAlignment:NSTextAlignmentLeft];
    _high.adjustsFontSizeToFitWidth = YES;
    _high.minimumScaleFactor = 0.5;
        
    [_low setFont:font];
    [_low setBackgroundColor:[UIColor clearColor]];
    [_low setTextColor:[UIColor greenColor]];
    [_low setTextAlignment:NSTextAlignmentLeft];
    _low.adjustsFontSizeToFitWidth = YES;
    _low.minimumScaleFactor = 0.5;

    [_close setFont:font];
    [_close setBackgroundColor:[UIColor clearColor]];
    [_close setTextColor:[UIColor blackColor]];
    [_close setTextAlignment:NSTextAlignmentLeft];
    _close.adjustsFontSizeToFitWidth = YES;
    _close.minimumScaleFactor = 0.5;
    
    [_date setFont:[UIFont systemFontOfSize:13]];
    [_date setBackgroundColor:[UIColor clearColor]];
    [_date setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
    [_date setTextAlignment:NSTextAlignmentRight];
    _date.adjustsFontSizeToFitWidth = YES;
    _date.minimumScaleFactor = 0.5;
    

    }else{
        UIFont *font = [UIFont systemFontOfSize:10.0];
        _openName = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 11, 33)];
        _highName = [[UILabel alloc] initWithFrame:CGRectMake(132, 0, 11, 33)];
        _lowName = [[UILabel alloc] initWithFrame:CGRectMake(194, 0, 11, 33)];
        _closeName = [[UILabel alloc] initWithFrame:CGRectMake(256, 0, 11, 33)];
        _dateName = [[UILabel alloc] initWithFrame:CGRectMake(8, 15, 60, 15)];
        
        _highName.text = @"高";
        [_highName setFont:font];
        [_highName setBackgroundColor:[UIColor clearColor]];
        [_highName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
        
        _lowName.text = @"低";
        [_lowName setFont:font];
        [_lowName setBackgroundColor:[UIColor clearColor]];
        [_lowName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
        
        _openName.text = @"开";
        [_openName setFont:font];
        [_openName setBackgroundColor:[UIColor clearColor]];
        [_openName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
        
        _closeName.text = @"收";
        [_closeName setFont:font];
        [_closeName setBackgroundColor:[UIColor clearColor]];
        [_closeName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
        
        [_dateName setFont:[UIFont systemFontOfSize:11.0]];
        [_dateName setBackgroundColor:[UIColor clearColor]];
        [_dateName setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
         
        
            _open = [[UILabel alloc] initWithFrame:CGRectMake(81, 0, 51, 33)];
            _high = [[UILabel alloc] initWithFrame:CGRectMake(143, 0, 51, 33)];
            _low = [[UILabel alloc] initWithFrame:CGRectMake(205, 0, 51, 33)];
            _close = [[UILabel alloc] initWithFrame:CGRectMake(267, 0, 51, 33)];
            _date = [[UILabel alloc] initWithFrame:CGRectMake(3, 0, 60, 33)];
            
    
        [_open setFont:font];
        [_open setBackgroundColor:[UIColor clearColor]];
        [_open setTextColor:[UIColor blackColor]];
        [_open setTextAlignment:NSTextAlignmentLeft];
        _open.adjustsFontSizeToFitWidth = YES;
        _open.minimumScaleFactor = 0.5;
        
        
        [_high setFont:font];
        [_high setBackgroundColor:[UIColor clearColor]];
        [_high setTextColor:[UIColor redColor]];
        [_high setTextAlignment:NSTextAlignmentLeft];
        _high.adjustsFontSizeToFitWidth = YES;
        _high.minimumScaleFactor = 0.5;
        
        [_low setFont:font];
        [_low setBackgroundColor:[UIColor clearColor]];
        [_low setTextColor:[UIColor greenColor]];
        [_low setTextAlignment:NSTextAlignmentLeft];
        _low.adjustsFontSizeToFitWidth = YES;
        _low.minimumScaleFactor = 0.5;
        
        [_close setFont:font];
        [_close setBackgroundColor:[UIColor clearColor]];
        [_close setTextColor:[UIColor blackColor]];
        [_close setTextAlignment:NSTextAlignmentLeft];
        _close.adjustsFontSizeToFitWidth = YES;
        _close.minimumScaleFactor = 0.5;
        
        [_date setFont:[UIFont systemFontOfSize:11.0]];
        [_date setBackgroundColor:[UIColor clearColor]];
        [_date setTextColor:[AFUtils UIColorFromRGB:0x989fb7 alpha:1.0]];
        [_date setTextAlignment:NSTextAlignmentRight];
        _date.adjustsFontSizeToFitWidth = YES;
        _date.minimumScaleFactor = 0.5;
        
       
    }
    [_showInfo addSubview:_highName];
    [_showInfo addSubview:_lowName];
    [_showInfo addSubview:_openName];
    [_showInfo addSubview:_closeName];
//    [_showInfo addSubview:_dateName];
    
    [_showInfo addSubview:_high];
    [_showInfo addSubview:_low];
    [_showInfo addSubview:_open];
    [_showInfo addSubview:_close];
    [_showInfo addSubview:_date];
    _showInfo.layer.borderWidth = 1.0f;
        [_showInfo setBackgroundColor:K_M_SOCIAL_VIEW_BG];
        _showInfo.layer.borderColor = [AFUtils UIColorFromRGB:0xeaeaea alpha:1.0].CGColor;


}

-(void)finagerMoveX:(float)x{
    if(x > [AFSetting QUARTZ_KLINE_W]){
        NSLog(@"ddD");
        return;
    }
    if (fingerType == AF_K_MARKET_FINGER_VIEW_TYPE_TIME) {
        [line1 setFrame:CGRectMake(x, TIME_LINE_1_Y, TIME_LINE_W, TIME_LINE_1_H)];
        [line2 setFrame:CGRectMake(x, TIME_LINE_2_Y, TIME_LINE_W, TIME_LINE_2_H)];
    } else {
        [line1 setFrame:CGRectMake(x, KLINE_LINE_1_Y, KLINE_LINE_W, KLINE_LINE_1_H)];
        [line2 setFrame:CGRectMake(x, KLINE_LINE_2_Y, KLINE_LINE_W, KLINE_LINE_2_H)];
       
        if(point_y >= KLINE_LINE_1_Y && point_y <= KLINE_LINE_1_Y + [AFSetting QUARTZ_KLINE_H]){
            line3.hidden = NO;
//            pointImage.hidden = NO;
            PointLab.hidden = NO;
          [line3 setFrame:CGRectMake(0, point_y, [AFSetting QUARTZ_KLINE_W], KLINE_LINE_W)];
//          [pointImage setFrame:CGRectMake(point_x - 6, point_y - 6, 12, 12)];
          [PointLab  setFrame:CGRectMake([AFSetting QUARTZ_KLINE_W], point_y - 8 , 45, 15)];
            float last_KLineHigh = [[AFMarketData data] lastKLineHigh];
            float last_KLineLow = [[AFMarketData data] lastKLineLow];
            float with_min = (last_KLineHigh - last_KLineLow) / [AFSetting QUARTZ_KLINE_H];
            float value = last_KLineHigh - (point_y - KLINE_LINE_1_Y) * with_min;
            PointLab.text = [NSString stringWithFormat:[AFMarketData data].code_decimal,value];

        }else if(point_y >= KLINE_LINE_2_Y && point_y <= KLINE_LINE_2_Y + [AFSetting QUARTZ_KPI_H]){
            line3.hidden = NO;
//            pointImage.hidden = NO;
            PointLab.hidden = NO;
            
            [line3 setFrame:CGRectMake(0, point_y, [AFSetting QUARTZ_KLINE_W], KLINE_LINE_W)];
//            [pointImage setFrame:CGRectMake(point_x - 6, point_y - 6, 12, 12)];
            [PointLab  setFrame:CGRectMake([AFSetting QUARTZ_KLINE_W], point_y - 8 , 45, 15)];
            if(kpi1 != kpi2){
            float with_min = (kpi1 - kpi2) / [AFSetting QUARTZ_KPI_H];
            float value = kpi1 - (point_y - KLINE_LINE_2_Y) * with_min;
                if(kpiType == 2){
                PointLab.text = [NSString stringWithFormat:@"%.2f万",value];
                }else{
                 PointLab.text = [NSString stringWithFormat:@"%.2f",value];
                }
            }else{
                if(kpiType == 2){
                    PointLab.text = [NSString stringWithFormat:@"%.2f万",kpi1];
                }else{
                    PointLab.text = [NSString stringWithFormat:@"%.2f",kpi1];
                }
            }
            
        }
        else{
            line3.hidden = YES;
//            pointImage.hidden = YES;
            PointLab.hidden = YES;
        }
    }
    
    if (x > K_FINGER_CENTER_X) {
        if (fingerType == AF_K_MARKET_FINGER_VIEW_TYPE_TIME) {
            [_showInfo setFrame:RECT_TIME_INFO];
        } else {
//            [_showInfo setFrame:RECT_KLINE_INFO_RIGHT];
              [_showInfo setFrame:RECT_KLINE_INFO];
        }
    } else {
        if (fingerType == AF_K_MARKET_FINGER_VIEW_TYPE_TIME) {
            [_showInfo setFrame:RECT_TIME_INFO_RIGHT];
        } else {
            [_showInfo setFrame:RECT_KLINE_INFO];
        }
    }
}

-(void)kLineLastRefresh{
    
    if (_showInfo == nil) {
        return;
    }
    
    if ([_showInfo isHidden]) {
        return;
    }
    
    [self fingerKLineDataRefreshWithX:point_x withY:point_y];
}


// 按照 当前 x 坐标 刷新数据
-(void)fingerKLineDataRefreshWithX:(float)x withY:(float)y{
    
    point_x = x;
    point_y = y;
    
    [self finagerMoveX:x];
    
    if([self.delegate respondsToSelector:@selector(afFinagerMoveX:)]){
        [self.delegate afFinagerMoveX:x];
    }
}

-(void)fingerKLineDataRefresh:(NSDictionary*)dict preData:(NSDictionary *)_predict kLineType:(NSString*)kLineType codeDecimalFormat:(NSString*)format{
    
    if ([[dict objectForKey:AF_K_MARKET_CLOSE] floatValue] == 0) {
        _showInfo.hidden = YES;
        _volume.hidden = YES;
        [MarketKpiInfo manager].kpiInfoView.hidden = YES;
        [MarketKpiInfo manager].kpiLab.hidden = NO;
        
        return;
    } else {
        _showInfo.hidden = NO;
        _volume.hidden = NO;
        [MarketKpiInfo manager].kpiInfoView.hidden = NO;
        [MarketKpiInfo manager].kpiLab.hidden = YES;
    }
    
    if(_predict){
     NSDecimalNumber * number_lastClose = [[NSDecimalNumber alloc] initWithString:[_predict objectForKey:AF_K_MARKET_CLOSE]];
    NSDecimalNumber * number_open = [[NSDecimalNumber alloc] initWithString:[dict objectForKey:AF_K_MARKET_OPEN]];
    NSDecimalNumber * number_close = [[NSDecimalNumber alloc] initWithString:[dict objectForKey:AF_K_MARKET_CLOSE]];
     NSDecimalNumber * number_hight = [[NSDecimalNumber alloc] initWithString:[dict objectForKey:AF_K_MARKET_HIGH]];
     NSDecimalNumber * number_low = [[NSDecimalNumber alloc] initWithString:[dict objectForKey:AF_K_MARKET_LOW]];
    result = [number_open compare:number_lastClose];
    
    if (result == NSOrderedDescending) {    // 涨
        _open.textColor = K_MARKET_UPFONT_COLOR;
      
    } else if (result == NSOrderedSame) {   // 平
        _open.textColor = K_APP_LIST_FONT_COLOR;

    } else {                                // 跌
        _open.textColor = K_MARKET_DOWNFONT_COLOR;
    }
        
        result = [number_close compare:number_lastClose];
        if (result == NSOrderedDescending) {    // 涨
            _close.textColor = K_MARKET_UPFONT_COLOR;
            
        } else if (result == NSOrderedSame) {   // 平
                _close.textColor = K_APP_LIST_FONT_COLOR;

        } else {                                // 跌
            _close.textColor = K_MARKET_DOWNFONT_COLOR;
        }
        
        result = [number_hight compare:number_lastClose];
        if (result == NSOrderedDescending) {    // 涨
            _high.textColor = K_MARKET_UPFONT_COLOR;
            
        } else if (result == NSOrderedSame) {   // 平
                _high.textColor = K_APP_LIST_FONT_COLOR;

        } else {                                // 跌
            _high.textColor = K_MARKET_DOWNFONT_COLOR;
        }
        
        result = [number_low compare:number_lastClose];
        if (result == NSOrderedDescending) {    // 涨
            _low.textColor = K_MARKET_UPFONT_COLOR;
            
        } else if (result == NSOrderedSame) {   // 平
            _low.textColor = K_APP_LIST_FONT_COLOR;

        } else {                                // 跌
            _low.textColor = K_MARKET_DOWNFONT_COLOR;
        }
    
    

    }else{
        _open.textColor = K_APP_LIST_FONT_COLOR;
        _close.textColor = K_APP_LIST_FONT_COLOR;
         _high.textColor = K_APP_LIST_FONT_COLOR;
        _low.textColor = K_APP_LIST_FONT_COLOR;

    }
    
    _open.text = [NSString stringWithFormat:format, [[dict objectForKey:AF_K_MARKET_OPEN] floatValue]];
    _close.text = [NSString stringWithFormat:format, [[dict objectForKey:AF_K_MARKET_CLOSE] floatValue]];
    _high.text = [NSString stringWithFormat:format, [[dict objectForKey:AF_K_MARKET_HIGH] floatValue]];
    _low.text = [NSString stringWithFormat:format, [[dict objectForKey:AF_K_MARKET_LOW] floatValue]];

    // 1d 1w 1m 5m 15m 30m 60m,  default is 1d
    if ([kLineType isEqualToString:@"day"]
        || [kLineType isEqualToString:@"week"]) {
        if([AFSetting QUARTZ_KLINE_W] >= 270){
        _date.text =  [AFUtils unixTimePoint:[dict objectForKey:AF_K_MARKET_UPDATETIME]];
        }else{
            _date.frame = CGRectMake(3, 0, 60, 33);
            _date.text =  [AFUtils unixTimePoint:[dict objectForKey:AF_K_MARKET_UPDATETIME]];
            _dateName.text = @"";
        }
        
    } else {
         if([AFSetting QUARTZ_KLINE_W] >= 270){
        _date.text =  [AFUtils unixTimePointYYYYMMDDHHMM:[dict objectForKey:AF_K_MARKET_UPDATETIME]];
             
         }else{
             //              _date.frame = CGRectMake(3, 5, 60, 18);
             _date.frame = CGRectMake(3, 0, 60, 33);
             NSString *dateTime = [AFUtils unixTimePointYYYYMMDDHHMM:[dict objectForKey:AF_K_MARKET_UPDATETIME]];
             _date.text = [dateTime substringFromIndex:5];
             //             NSArray *_timeArray = [dateTime componentsSeparatedByString:@" "];
             //             _date.text = [_timeArray objectAtIndex:0];
             //             _dateName.text = [_timeArray objectAtIndex:1];

         }
    }
}


-(void)fingerKpiDataRefresh:(AFKpiQuartzView *)kpiquart kpiType:(int)kpi{
    kpiType = kpi;
    if (kpi == 0) {
        kpi1 = [[NSString stringWithFormat:@"%.2f", [kpiquart macdMax]] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", [kpiquart macdMin]] floatValue];
    }
    else if (kpi == 1) {
        float _maxvol = [kpiquart volMax];
        float _max = _maxvol/10000;
        kpi1 = [[NSString stringWithFormat:@"%.2f", _max] floatValue];
        kpi2 = 0;
    }
    else if (kpi == 2) {
        float _minRsi = [kpiquart rsiMin];
        float _maxRsi = [kpiquart rsiMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxRsi] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minRsi] floatValue];
    }
    else if (kpi == 3) {
        float _minBool = [kpiquart boolMin];
        float _maxBool = [kpiquart boolMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxBool] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minBool] floatValue];
    }
    else if (kpi == 4) {
        float _minKdj = [kpiquart kdjMin];
        float _maxKdj = [kpiquart kdjMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxKdj] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minKdj] floatValue];
    }
    else if (kpi == 5) {
        float _minObv = [kpiquart obvMin];
        float _maxObv = [kpiquart obvMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxObv] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minObv] floatValue];
    }
    else if (kpi == 6) {
        float _minCci = [kpiquart cciMin];
        float _maxCci = [kpiquart cciMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxCci] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minCci] floatValue];
    }
    else if (kpi == 7) {
        float _minPsy = [kpiquart psyMin];
        float _maxPsy = [kpiquart psyMax];
        
        kpi1 = [[NSString stringWithFormat:@"%.2f", _maxPsy] floatValue];
        kpi2 = [[NSString stringWithFormat:@"%.2f", _minPsy] floatValue];
    }

}

-(void) destioy{
    [line1 removeFromSuperview];
    [line2 removeFromSuperview];
    [line3 removeFromSuperview];
//    [pointImage removeFromSuperview];
    [PointLab removeFromSuperview];
    [MarketKpiInfo manager].kpiInfoView.hidden = YES;
    [MarketKpiInfo manager].kpiLab.hidden = NO;
    line1 = nil;
    line2 = nil;
    line3 = nil;
//    pointImage = nil;
    PointLab = nil;
    // time
    //[_priceLab removeFromSuperview];
    //[_averageLab removeFromSuperview];
    //[_dateLab removeFromSuperview];
    
    //[_price removeFromSuperview];
    //[_average removeFromSuperview];
    
    [_volume removeFromSuperview];
    _volume = nil;
    
    [_showInfo removeFromSuperview];
    _showInfo = nil;
}

@end
